<template>
	<div id="express_sheet">
		<el-form :inline="true" size="medium">
			<el-form-item>
				<el-select v-model="params.storeId" placeholder="选择仓库" clearable @change="search">
					<el-option :value="item.id" :label="item.name" v-for="(item, index) in goodsStoreList"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-select v-model="params.expressStatus" placeholder="选择面单类型" clearable @change="search">
					<el-option value="1" label="通用电子面单"></el-option>
					<el-option value="2" label="菜鸟电子面单"></el-option>
					<el-option value="3" label="拼多多面单"></el-option>
					<el-option value="0" label="其他"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-input v-model="params.shipperName" placeholder="快递公司名称"></el-input>
			</el-form-item>
			
			<el-form-item>
				<el-button type="primary" @click="search">搜索</el-button>
				<!-- <el-button>添加</el-button> -->
			</el-form-item>
		</el-form>

		<el-table :data="list" v-loading="loading" stripe>
			<el-table-column label="id" prop="id" align="center"></el-table-column>
			<el-table-column label="店铺id" prop="user_id" align="center">
				<template slot-scope="scope">
					{{scope.row.user_id || '--'}}
				</template>
			</el-table-column>
			<el-table-column label="所属仓库" prop="store_id" align="center">
				<template slot-scope="scope">
					{{selectStore(scope.row.store_id)}}
				</template>
			</el-table-column>
			<el-table-column label="面单类型" prop="express_status" align="center">
				<template slot-scope="scope">
					{{selectExpressType(scope.row.express_status)}}
				</template>
			</el-table-column>
			<el-table-column label="快递公司名称" prop="shipper_name" align="center"></el-table-column>
			<el-table-column label="网点名称" prop="company" align="center"></el-table-column>
			<el-table-column label="发货人" prop="name" align="center"></el-table-column>
			<el-table-column label="发货人手机/电话" prop="mobile" align="center">
				<template slot-scope="scope">
					<p>{{scope.row.mobile}}</p>
					<p>{{scope.row.tel}}</p>
				</template>
			</el-table-column>
			<el-table-column label="地址" align="center">
				<template slot-scope="scope">
					<p>{{scope.row.province_name}}</p>
					<p>{{scope.row.city_name}}</p>
					<p>{{scope.row.exp_area_name}}</p>
					<p>{{scope.row.address}}</p>
				</template>
			</el-table-column>
			
			<!-- <el-table-column label="操作" align="center">
				<template slot-scope="scope">
					<el-button type="text">修改</el-button>
					<el-button type="text" class="error" @click="del(scope.row.id)">删除</el-button>
				</template>
			</el-table-column> -->
		</el-table>

		<el-pagination 
			class="page"
			background
			@size-change="handleSizeChange" 
			@current-change="getList" 
			:current-page.sync="params.pageNo" 
			:page-sizes="[10, 20, 50, 100]" 
			:page-size="params.pageSize" 
			layout="total, sizes, prev, pager, next, jumper" 
			:total="total">
		</el-pagination>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				params: {
					pageNo: 1,
					pageSize: 10,
					isCount: true,
					expressStatus: '',
					shipperName: ''
				},
				list: [],
				total: 0,
				loading: false,
				goodsStoreList: []
			};
		},

		watch: {},

		create() {},

		mounted() {
			this.getList();
			this.getStore();
		},

		methods: {
			handleSizeChange(value) {
				this.params.pageSize = value 
				this.search()
			},
			
			search(){
				this.params.pageNo = 1
				this.params.isCount = true 
				this.getList();
			},
			
			getList() {
				this.loading = true
				this.$request.post({
					url: '/ReportApi/tenant/expresssheetlist',
					params: this.params,
					success: result =>{
						this.list = result[0]
						if(this.params.isCount){
							this.params.isCount = false 
							this.total = result[1]
						}
					},
					finally: ()=>{
						this.loading = false 
					}
				})
			},
			
			getStore() {
				this.$request.post({
					closeErrInfo: true,
					closeCodeInfo: true,
					url: '/ReportApi/tenant/expresssheetalllists',
					success: result => {
						this.goodsStoreList = result
					}
				})
			},
			
			del(id){
				this.$confirm('确认删除?', '提示').then(() => {
					this.$request.post({
						url: '/ReportApi/tenant/expresssheetdel',
						params: {
							id
						},
						success: () => {
							this.$message.success('操作成功')
							if (this.params.pageNo > 1 && this.list.length < 2) {
								this.params.pageNo--
							}
							this.getList();
						}
					})
				})
			},
			
			selectStore(storeId) {
				if (!this.goodsStoreList.length) {
					return;
				}
				var index = this.goodsStoreList.findIndex(item => item.id == storeId);
				if(index == -1){
					return ''
				}
				return this.goodsStoreList[index].name
			},
			
			selectExpressType(expressStatus){
				switch(expressStatus){
					case 1: 
						return "通用电子面单";
					case 2: 
						return "菜鸟电子面单";
					case 3: 
						return "拼多多面单";
					case 4: 
						return "京东面单";
					default: 
						return "其他面单";
				}
			}
			
		},

		beforeDestroy() {}
	}
</script>

<style>

</style>

<style lang="scss" scoped>
	.page{
		text-align: right;
		margin-top: 20px;
	}
</style>
